var keyMap = {};
//定义一个对象,将bom中的地址参数存下来,java中的map集合
var categoryId = location.search.substring(1);
categoryId.split('&').forEach(function (element) {
    var km = element.split('=');
    keyMap[km[0]] = km[1];
}, this);

var categoryname = decodeURI(keyMap.category) + "\>";
$(function(){
    console.log(keyMap);
    // console.log(decodeURI(keyMap.category));

    $('.categoryname').text(categoryname);
    $.get('http://127.0.0.1:3000/api/getproduct?productid='+keyMap.productid,function(data){
       data = data.result;
    //    console.log(data);
       var str = $('.product_info').clone(true);
       $('.product_info').remove();
       //切割产品标题,得到详情页标题;
       var proName = data[0].productName.split(" ");
       str.find('.productName').text(data[0].productName);
    //    console.log(data[0].categoryId);
       //设置跳转页面,和渲染标题;
       $(document).find('.categoryname').attr('href','productlist.html?categoryid='+data[0].categoryId);
       $(document).find('.proName').text(proName[0]);
       $('.product_show').append(str);
       $(data[0].productImg).insertBefore($('.params'));
        $('.product_info').append(data[0].bjShop);
        $('.product_info').append($('article'));
    })
    $.get('http://127.0.0.1:3000/api/getproductcom?productid='+keyMap.productid,function(data){
        data = data.result;
        console.log(data);
        var len = data.length;
        console.log(len);
        var strs = $('.discuss_info').clone(true);
        
        $('.discuss_info').remove();
        for(var i = 0;i < len ; i++){
            var ss = strs.clone(true);
            strs.clone(true);
            var idata = data[i];
            console.log(idata);
            ss.find('.person').text(idata.comName);
            ss.find('.date').text(idata.comTime);
            ss.find('.comform').text(idata.comFrom);
            ss.find('.comm').text(idata.comContent);
            console.log(strs);
        $('.discuss').append(ss);
        }
    })
})